package com.m.job.server.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.client.job.core.model.MJobInstance;
import com.client.job.utils.MJobUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class MJobInstanceDto extends MJobInstance {
	
	
	private Date createTime;
	
	private Date updateTime;
	
	private String createBy;
	
	private String updateBy;
	
	private String remark;
	
	public String getServerInfo() {
		return MJobUtils.genServerFlag(this.getAppName(), this.getPort());
	}
	
	/**
	 * 构建Dto
	 * @param MJobInstance
	 * @return
	 */
	public static MJobInstanceDto  buildNewDto(MJobInstance MJobInstance) {
		MJobInstanceDto dto = poToDto(MJobInstance);
		dto.setCreateTime(new Date());
		dto.setUpdateTime(new Date());
		return dto;
	}
	
	public static MJobInstance dtoToPo(MJobInstanceDto dto) {
		return dto;
	}
	
	public static List<MJobInstance> dtoListToPoList(List<MJobInstanceDto> dtoList){
		List<MJobInstance>  poList  = new ArrayList<>();
		dtoList.forEach( o ->{
			poList.add(o);
		});
		return poList;
	}
	
	
	
	private static MJobInstanceDto poToDto(MJobInstance mJobInstance) {
		MJobInstanceDto dto = new MJobInstanceDto();
		dto.setMachineId(mJobInstance.getMachineId());
		dto.setMachineIp(mJobInstance.getMachineIp());
		dto.setPort(mJobInstance.getPort());
		dto.setBasePath(mJobInstance.getBasePath());
		dto.setAppName(mJobInstance.getAppName());
		dto.setMachineTime(mJobInstance.getMachineTime());
		dto.setJobId(mJobInstance.getJobId());
		dto.setJobName(mJobInstance.getJobName());
		dto.setJobStatus(mJobInstance.getJobStatus());
		dto.setSort(mJobInstance.getSort());
		dto.setServerStatus(mJobInstance.getServerStatus());
		return dto;
	}
	
	

}
